package com.shop.loan.model.view;

import com.shop.loan.model.Channel;
import com.shop.loan.proxy.LoanOrderByChannelProxy;
import com.shop.loan.util.LoanOrderUtil;
import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.Readonly;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.ChoiceType;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.annotation.sub_field.sub_edit.VL;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

@Setter
@Getter
@Entity
@Table(name = "s_loan_order")
@Erupt(
        name = "订单信息",
        filter = @Filter("LoanOrderByChannel.isDelete = false"),
        power = @Power(add = false, edit = false, delete = false, viewDetails = false),
        authVerify = false,
        dataProxy = LoanOrderByChannelProxy.class
)
@ApiModel("渠道订单")
public class LoanOrderByChannel extends BaseModel {


    @Transient
    @EruptField(
            edit = @Edit(
                    title = "姓名",
                    search = @Search(vague = true)
            )
    )
    private String userName;

//    @ManyToOne
//    @EruptField(
//            views = @View(title = "用户", column = "mobile"),
//            edit = @Edit(
//                    title = "手机号码",
//                    show = false,
//                    type = EditType.REFERENCE_TREE,
//                    referenceTreeType = @ReferenceTreeType(label = "mobile")
//            )
//    )
//    @JoinColumn(name = "user_id")
//    private User user;

    @EruptField(
            views = @View(title = "用户id", show = false)
    )
    @Column(name = "user_id")
    private Long userId;

    @Transient
    @EruptField(
            views = @View(title = "借款用户", width = LoanOrderUtil.orderListByUserWidth)
    )
    private String user_name;


    @EruptField(
            views = @View(title = "订单状态", width = LoanOrderUtil.orderListByStatusWidth),
            edit = @Edit(
                    title = "订单状态",
                    type = EditType.CHOICE,
                    search = @Search,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(label = "审核中", value = "1"),
                                    @VL(label = "审核拒绝", value = "2"),
                                    @VL(label = "待签署", value = "3"),
                                    @VL(label = "待放款", value = "4"),
                                    @VL(label = "放款驳回", value = "5"),
                                    @VL(label = "待还款", value = "7"),
                                    @VL(label = "已结束", value = "10"),
                            }
                    ))
    )
    private Integer status;

    @EruptField(
            views = @View(title = "借款金额", width = LoanOrderUtil.orderListByMoneyWidth),
            edit = @Edit(title = "借款金额", notNull = true)
    )
    private BigDecimal money;


    @ManyToOne
    @EruptField(
            edit = @Edit(
                    title = "渠道",
                    show = false,
                    type = EditType.REFERENCE_TREE
            )
    )
    @JoinColumn(name = "channel_id")
    private Channel channel;


    @EruptField(
            views = @View(title = "创建时间"),
            edit = @Edit(title = "创建时间",
                    search = @Search(vague = true),
                    readonly = @Readonly,
                    dateType = @DateType(type = DateType.Type.DATE_TIME))
    )
    private Date createTime;

    private Boolean channelStatistics = true;

    private Boolean isDelete = false;

    private Date deleteTime;

}
